package org.cdivtc.exam.service.impl;

import org.cdivtc.exam.entity.Admins;
import org.cdivtc.exam.mapper.AdminsMapper;
import org.cdivtc.exam.service.AdminsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 系统管理员信息表 服务实现类
 * </p>
 *
 * @author xiaogoudashuai
 * @since 2025-03-27
 */
@Service
public class AdminsServiceImpl extends ServiceImpl<AdminsMapper, Admins> implements AdminsService {

    @Autowired
    private AdminsMapper adminsMapper;

    @Override
    public Map<String, Object> login(String account, String password) {
        Map<String, Object> result = new HashMap<>();

        // 1. 根据账号查询教师
       Admins admins = adminsMapper.selectByAccount(account);
        if (admins == null) {
            result.put("success", false);
            result.put("message", "账号不存在");
            return result;
        }

        // 2. 验证密码（简化版，实际项目应加密比对）
        if (!password.equals(admins.getPassword())) {
            result.put("success", false);
            result.put("message", "密码错误");
            return result;
        }

        // 3. 登录成功，返回教师基本信息
        result.put("success", true);
        result.put("data", admins);
        return result;
    }
}
